"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from dataclasses import dataclass, field
from datetime import datetime

from sqlalchemy import *
from sqlalchemy.orm import relationship

# from orm_domain import Job, Runner
# from orm_domain.job import Job
from orm_domain.runner import Runner
from server import mapper_registry


@mapper_registry.mapped
@dataclass
class Execution:
    __tablename__ = "execution"
    __sa_dataclass_metadata_key__ = "sa"

    id: int = field(init=False, metadata={"sa": Column(Integer, primary_key=True)}, )
    # 外键 指向job 表
    job_id: int = field(default=None, metadata={"sa": Column(Integer, ForeignKey("job.id"))}, )
    runner_id: int = field(default=None, metadata={"sa": Column(Integer, ForeignKey("runner.id"))}, )
    execution_count: int = field(default=None, metadata={"sa": Column(Integer)}, )
    create_time: datetime = field(init=False,
                                  metadata={"sa": Column(DateTime, nullable=True, default=datetime.now)}, )
    remark: str = field(default=None, metadata={"sa": Column(String(255))}, )
    runner_obj: Runner = field(init=False, metadata={"sa": relationship("Runner", backref="execution")}, )
